import * as echarts from "../../components/ec-canvas/echarts"
let Chart = null;
Component({
    data: {
        weatherData: [{
                name: '周一',
                date: '01-04',
                status: '晴'
            },
            {
                name: '周二',
                date: '01-05',
                status: '雨'
            },
            {
                name: '周三',
                date: '01-06',
                status: '多云'
            },
            {
                name: '周四',
                date: '01-07',
                status: '晴'
            },
            {
                name: '周五',
                date: '01-08',
                status: '晴'
            }
        ],
        echartsData: {
            color: ["#F7DD8A"],
            grid: {
                left: '0',
                right: '0'
            },
            xAxis: {
                type: 'category',
                boundaryGap: ['10%', '10%'],
                show: false
            },
            yAxis: {
                min: 'dataMin',
                max: function(value) {
                    return value.max + 10;
                },
                show: false
            },
            series: [{
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            textStyle: {
                                color: '#333'
                            },
                            formatter: function(params) {
                                return params.value + '°'
                            }
                        }
                    }
                },
                type: 'line',
                symbolSize: '4',
                data: [11, 20, -8, 40, 14]
            }]
        }
    },
    lifetimes: {
        ready() {
            this.echartsComponnet = this.selectComponent('#mychart-dom-bar')
            this.init_echarts();
        }
    },
    methods: {
        init_echarts() {
            this.echartsComponnet.init((canvas, width, height, dpr) => {
                Chart = echarts.init(canvas, null, {
                    width: width,
                    height: height,
                    devicePixelRatio: dpr
                });
                Chart.setOption(this.getOption());
                return Chart;
            });
        },
        getOption() {
            var option = this.data.echartsData
            return option;
        }
    },
    onUnload: function() {
        Chart = null
    }
})